brute force math number theory *1200

Please click on ads to support us..

C++ Code:

/*          <----------Kamlesh Singh Bisht---------->         */

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroint-loops")
#include <bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
#define f first
#define endl '\n'
#define s second
#define pb push_back
#define md 998244353
#define int long long
#define vi vector<int>
#define mod 1000000007
#define inf 1999999999999999999
#define vp vector<pair<int,int>>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define in(a) for(auto &i:a)cin>>i
#define dbg(x) cout<<#x<<"->"<<x<<endl
#define mem(a,val) memset(a,val,sizeof(a))
#define out(a)for(auto i:a)cout<<i<<" ";cout<<endl
#define ebg(x,y) cout<<#x<<"->"<<x<<" "<<#y<<"->"<<y<<endl

// typedef tree<int, nuint_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// // set -> less, greater , multiset -> less_equal , greater_equal
// // pbds.order_of_key (k) : Number of items strictly smainter than k.
//*pbds.find_by_order(k) : K-th element in a set (counting from zero).

/*
                        FOCUS on the PROBLEM
                        Not on the Standings.
*/

/*
//1->40         AC
-
//2->50         AC
//3->50 (Div4)  AC
-
//4->21 (Div4)  AC
//5->68 (Div4)  X
//6->10         AL
//7->60         X
//8->25         AL
//9->65         X
//10->45(1300)  X
-
//11->40        X
//12->50        X
//13->40        X
//14->60        X
-
//15->25(Div3)  AC
//16->60        X
//17->50        X
-
//18->70(Div3)  X
//19->50        WA
//19->90(1300)  WA
-
//20->20        AC
//21->25        AC
//21->50(1000)  X
//21->45(1300)  AC
//21->50(1300)  X
-
//21->50(1300)  AC
//21->60(1300)  WA
-



*/

void solve() {
//Thanks CMC for the intuitive & Clean COde.

    int n, x, y; cin >> n >> x >> y;

    int diff = y - x;
    int k = 0;
    for (int i = 1; i <= diff; i++) {
        if (diff % i)continue;
        int terms = diff / i + 1;
        if (terms > n)continue;
        k = i;
        break;
    }

    vi ans;
    for (int i = x; i <= y; i += k) {
        ans.pb(i);
    }
    for (int i = x - k; i > 0 && ans.size() < n; i -= k) {
        ans.pb(i);
    }
    for (int i = y + k; ans.size() < n; i += k) {
        ans.pb(i);
    }
    out(ans);


}

int32_t main()
{

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    //Modulo Multiplicative Inverse
    // (a/b)%m;

    // (a*(b^(-1)))%m;
    // b^(-1) = (b^(m-2))%m;

    //Input of sqrt is double,long double.
    //if long long int is passed it will consider it as double not long double. so typecast input to long double in case of long long int.

    int t = 1;
    cin >> t;

    while (t--) {

        solve();


    }

    return 0;
}



Comments

Submit
0 Comments
More Questions

630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation
550C - Divisibility by Eight
5A - Chat Servers Outgoing Traffic
615A - Bulbs
5B - Center Alignment
549A - Face Detection
535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading
141B - Hopscotch
47B - Coins
1466C - Canine poetry
74A - Room Leader
1333D - Challenges in school №41
1475B - New Year's Number
461A - Appleman and Toastman
320B - Ping-Pong (Easy Version)
948A - Protect Sheep
387A - George and Sleep
53A - Autocomplete
1729G - Cut Substrings
805B - 3-palindrome
805C - Find Amir